﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:LOAN_MAIN
	/// </summary>
	public partial class LOAN_MAIN : BaseDAL<GSLMS.Entity.TB_LOAN_MAIN>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public LOAN_MAIN()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_LOAN_MAIN model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_APPLYNO", model.APPLYNO),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTNO", model.CUSTNO),
								new OracleParameter("P_PRODUCTID", model.PRODUCTID),
								new OracleParameter("P_PRODUCTNAME", model.PRODUCTNAME),
								new OracleParameter("P_FIELDPROJECT", model.FIELDPROJECT),
								new OracleParameter("P_LOANNO", model.LOANNO),
								new OracleParameter("P_SIGNDATE", model.SIGNDATE),
								new OracleParameter("P_APPLYBY", model.APPLYBY),
								new OracleParameter("P_APPLYBYNAME", model.APPLYBYNAME),
								new OracleParameter("P_APPLYDATE", model.APPLYDATE),
								new OracleParameter("P_BUSSTYPE", model.BUSSTYPE),
								new OracleParameter("P_CUSTNAME2", model.CUSTNAME2),
								new OracleParameter("P_CORPADDR", model.CORPADDR),
								new OracleParameter("P_AMT", model.AMT),
								new OracleParameter("P_LOANPHASE", model.LOANPHASE),
								new OracleParameter("P_LOANPHASETYPE", model.LOANPHASETYPE),
								new OracleParameter("P_LOANFEERATE", model.LOANFEERATE),
								new OracleParameter("P_RATE", model.RATE),
								new OracleParameter("P_MANAGERATE", model.MANAGERATE),
								new OracleParameter("P_MEDIATORID", model.MEDIATORID),
								new OracleParameter("P_MEDIATOR", model.MEDIATOR),
								new OracleParameter("P_MEDIATORACCOUNT", model.MEDIATORACCOUNT),
								new OracleParameter("P_PROMANAGER", model.PROMANAGER),
								new OracleParameter("P_RISKMANAGER", model.RISKMANAGER),
								new OracleParameter("P_LENDER", model.LENDER),
								new OracleParameter("P_LENDORCORP", model.LENDORCORP),
								new OracleParameter("P_RISKSTEP", model.RISKSTEP),
								new OracleParameter("P_LOANPAYMENT", model.LOANPAYMENT),
								new OracleParameter("P_SPECAILREMARK", model.SPECAILREMARK),
								new OracleParameter("P_LOANDATE", model.LOANDATE),
								new OracleParameter("P_ENDDATE", model.ENDDATE),
								new OracleParameter("P_RECCHARGES", model.RECCHARGES),
								new OracleParameter("P_ISDEDUCTION", model.ISDEDUCTION),
								new OracleParameter("P_DEDFEES", model.DEDFEES),
								new OracleParameter("P_ACTAMT", model.ACTAMT),
								new OracleParameter("P_CHECKBY", model.CHECKBY),
								new OracleParameter("P_CHECKBYNAME", model.CHECKBYNAME),
								new OracleParameter("P_CHECKDATE", model.CHECKDATE),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_TOUSER", model.TOUSER),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_LOANSTATUS", model.LOANSTATUS),
								new OracleParameter("P_CONFIRMBY", model.CONFIRMBY),
								new OracleParameter("P_CONFIRMDATE", model.CONFIRMDATE),
								new OracleParameter("P_RETURNSTATUS", model.RETURNSTATUS)};
  
			for (int i = 0; i < 49; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_main_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_LOAN_MAIN model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_APPLYNO", model.APPLYNO),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTNO", model.CUSTNO),
								new OracleParameter("P_PRODUCTID", model.PRODUCTID),
								new OracleParameter("P_PRODUCTNAME", model.PRODUCTNAME),
								new OracleParameter("P_FIELDPROJECT", model.FIELDPROJECT),
								new OracleParameter("P_LOANNO", model.LOANNO),
								new OracleParameter("P_SIGNDATE", model.SIGNDATE),
								new OracleParameter("P_APPLYBY", model.APPLYBY),
								new OracleParameter("P_APPLYBYNAME", model.APPLYBYNAME),
								new OracleParameter("P_APPLYDATE", model.APPLYDATE),
								new OracleParameter("P_BUSSTYPE", model.BUSSTYPE),
								new OracleParameter("P_CUSTNAME2", model.CUSTNAME2),
								new OracleParameter("P_CORPADDR", model.CORPADDR),
								new OracleParameter("P_AMT", model.AMT),
								new OracleParameter("P_LOANPHASE", model.LOANPHASE),
								new OracleParameter("P_LOANPHASETYPE", model.LOANPHASETYPE),
								new OracleParameter("P_LOANFEERATE", model.LOANFEERATE),
								new OracleParameter("P_RATE", model.RATE),
								new OracleParameter("P_MANAGERATE", model.MANAGERATE),
								new OracleParameter("P_MEDIATORID", model.MEDIATORID),
								new OracleParameter("P_MEDIATOR", model.MEDIATOR),
								new OracleParameter("P_MEDIATORACCOUNT", model.MEDIATORACCOUNT),
								new OracleParameter("P_PROMANAGER", model.PROMANAGER),
								new OracleParameter("P_RISKMANAGER", model.RISKMANAGER),
								new OracleParameter("P_LENDER", model.LENDER),
								new OracleParameter("P_LENDORCORP", model.LENDORCORP),
								new OracleParameter("P_RISKSTEP", model.RISKSTEP),
								new OracleParameter("P_LOANPAYMENT", model.LOANPAYMENT),
								new OracleParameter("P_SPECAILREMARK", model.SPECAILREMARK),
								new OracleParameter("P_LOANDATE", model.LOANDATE),
								new OracleParameter("P_ENDDATE", model.ENDDATE),
								new OracleParameter("P_RECCHARGES", model.RECCHARGES),
								new OracleParameter("P_ISDEDUCTION", model.ISDEDUCTION),
								new OracleParameter("P_DEDFEES", model.DEDFEES),
								new OracleParameter("P_ACTAMT", model.ACTAMT),
								new OracleParameter("P_CHECKBY", model.CHECKBY),
								new OracleParameter("P_CHECKBYNAME", model.CHECKBYNAME),
								new OracleParameter("P_CHECKDATE", model.CHECKDATE),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_TOUSER", model.TOUSER),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_LOANSTATUS", model.LOANSTATUS),
								new OracleParameter("P_CONFIRMBY", model.CONFIRMBY),
								new OracleParameter("P_CONFIRMDATE", model.CONFIRMDATE),
								new OracleParameter("P_RETURNSTATUS", model.RETURNSTATUS)};
  
			for (int i = 0; i < 49; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_main_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_main_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_LOAN_MAIN DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_LOAN_MAIN model = new GSLMS.Entity.TB_LOAN_MAIN();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["CONID"]!=null && dr["CONID"].ToString()!="")
				{
					model.CONID=OracleHelper.ToLong(dr["CONID"].ToString());
				}
				if(dr["APPLYNO"]!=null && dr["APPLYNO"].ToString()!="")
				{
					model.APPLYNO=dr["APPLYNO"].ToString();
				}
				if(dr["CUSTNAME"]!=null && dr["CUSTNAME"].ToString()!="")
				{
					model.CUSTNAME=dr["CUSTNAME"].ToString();
				}
				if(dr["CUSTNO"]!=null && dr["CUSTNO"].ToString()!="")
				{
					model.CUSTNO=dr["CUSTNO"].ToString();
				}
				if(dr["PRODUCTID"]!=null && dr["PRODUCTID"].ToString()!="")
				{
					model.PRODUCTID=OracleHelper.ToLong(dr["PRODUCTID"].ToString());
				}
				if(dr["PRODUCTNAME"]!=null && dr["PRODUCTNAME"].ToString()!="")
				{
					model.PRODUCTNAME=dr["PRODUCTNAME"].ToString();
				}
				if(dr["FIELDPROJECT"]!=null && dr["FIELDPROJECT"].ToString()!="")
				{
                    model.FIELDPROJECT = OracleHelper.ToInt(dr["FIELDPROJECT"].ToString());
				}
				if(dr["LOANNO"]!=null && dr["LOANNO"].ToString()!="")
				{
					model.LOANNO=dr["LOANNO"].ToString();
				}
				if(dr["SIGNDATE"]!=null && dr["SIGNDATE"].ToString()!="")
				{
					model.SIGNDATE=DateTime.Parse(dr["SIGNDATE"].ToString());
				}
				if(dr["APPLYBY"]!=null && dr["APPLYBY"].ToString()!="")
				{
					model.APPLYBY=dr["APPLYBY"].ToString();
				}
				if(dr["APPLYBYNAME"]!=null && dr["APPLYBYNAME"].ToString()!="")
				{
					model.APPLYBYNAME=dr["APPLYBYNAME"].ToString();
				}
				if(dr["APPLYDATE"]!=null && dr["APPLYDATE"].ToString()!="")
				{
					model.APPLYDATE=DateTime.Parse(dr["APPLYDATE"].ToString());
				}
				if(dr["BUSSTYPE"]!=null && dr["BUSSTYPE"].ToString()!="")
				{
                    model.BUSSTYPE = OracleHelper.ToInt(dr["BUSSTYPE"].ToString());
				}
				if(dr["CUSTNAME2"]!=null && dr["CUSTNAME2"].ToString()!="")
				{
					model.CUSTNAME2=dr["CUSTNAME2"].ToString();
				}
				if(dr["CORPADDR"]!=null && dr["CORPADDR"].ToString()!="")
				{
					model.CORPADDR=dr["CORPADDR"].ToString();
				}
				if(dr["AMT"]!=null && dr["AMT"].ToString()!="")
				{
					model.AMT=OracleHelper.ToDecimal(dr["AMT"].ToString());
				}
				if(dr["LOANPHASE"]!=null && dr["LOANPHASE"].ToString()!="")
				{
                    model.LOANPHASE = OracleHelper.ToInt(dr["LOANPHASE"].ToString());
				}
				if(dr["LOANPHASETYPE"]!=null && dr["LOANPHASETYPE"].ToString()!="")
				{
                    model.LOANPHASETYPE = OracleHelper.ToInt(dr["LOANPHASETYPE"].ToString());
				}
				if(dr["LOANFEERATE"]!=null && dr["LOANFEERATE"].ToString()!="")
				{
					model.LOANFEERATE=OracleHelper.ToDecimal(dr["LOANFEERATE"].ToString());
				}
				if(dr["RATE"]!=null && dr["RATE"].ToString()!="")
				{
					model.RATE=OracleHelper.ToDecimal(dr["RATE"].ToString());
				}
				if(dr["MANAGERATE"]!=null && dr["MANAGERATE"].ToString()!="")
				{
					model.MANAGERATE=OracleHelper.ToDecimal(dr["MANAGERATE"].ToString());
				}
				if(dr["MEDIATORID"]!=null && dr["MEDIATORID"].ToString()!="")
				{
					model.MEDIATORID=OracleHelper.ToLong(dr["MEDIATORID"].ToString());
				}
				if(dr["MEDIATOR"]!=null && dr["MEDIATOR"].ToString()!="")
				{
					model.MEDIATOR=dr["MEDIATOR"].ToString();
				}
				if(dr["MEDIATORACCOUNT"]!=null && dr["MEDIATORACCOUNT"].ToString()!="")
				{
					model.MEDIATORACCOUNT=dr["MEDIATORACCOUNT"].ToString();
				}
				if(dr["PROMANAGER"]!=null && dr["PROMANAGER"].ToString()!="")
				{
					model.PROMANAGER=dr["PROMANAGER"].ToString();
				}
				if(dr["RISKMANAGER"]!=null && dr["RISKMANAGER"].ToString()!="")
				{
					model.RISKMANAGER=dr["RISKMANAGER"].ToString();
				}
				if(dr["LENDER"]!=null && dr["LENDER"].ToString()!="")
				{
					model.LENDER=dr["LENDER"].ToString();
				}
				if(dr["LENDORCORP"]!=null && dr["LENDORCORP"].ToString()!="")
				{
					model.LENDORCORP=dr["LENDORCORP"].ToString();
				}
				if(dr["RISKSTEP"]!=null && dr["RISKSTEP"].ToString()!="")
				{
					model.RISKSTEP=dr["RISKSTEP"].ToString();
				}
				if(dr["LOANPAYMENT"]!=null && dr["LOANPAYMENT"].ToString()!="")
				{
                    model.LOANPAYMENT = OracleHelper.ToInt(dr["LOANPAYMENT"].ToString());
				}
				if(dr["SPECAILREMARK"]!=null && dr["SPECAILREMARK"].ToString()!="")
				{
					model.SPECAILREMARK=dr["SPECAILREMARK"].ToString();
				}
				if(dr["LOANDATE"]!=null && dr["LOANDATE"].ToString()!="")
				{
					model.LOANDATE=DateTime.Parse(dr["LOANDATE"].ToString());
				}
				if(dr["ENDDATE"]!=null && dr["ENDDATE"].ToString()!="")
				{
					model.ENDDATE=DateTime.Parse(dr["ENDDATE"].ToString());
				}
				if(dr["RECCHARGES"]!=null && dr["RECCHARGES"].ToString()!="")
				{
					model.RECCHARGES=OracleHelper.ToDecimal(dr["RECCHARGES"].ToString());
				}
				if(dr["ISDEDUCTION"]!=null && dr["ISDEDUCTION"].ToString()!="")
				{
                    model.ISDEDUCTION = OracleHelper.ToInt(dr["ISDEDUCTION"].ToString());
				}
				if(dr["DEDFEES"]!=null && dr["DEDFEES"].ToString()!="")
				{
					model.DEDFEES=OracleHelper.ToDecimal(dr["DEDFEES"].ToString());
				}
				if(dr["ACTAMT"]!=null && dr["ACTAMT"].ToString()!="")
				{
					model.ACTAMT=OracleHelper.ToDecimal(dr["ACTAMT"].ToString());
				}
				if(dr["CHECKBY"]!=null && dr["CHECKBY"].ToString()!="")
				{
					model.CHECKBY=dr["CHECKBY"].ToString();
				}
				if(dr["CHECKBYNAME"]!=null && dr["CHECKBYNAME"].ToString()!="")
				{
					model.CHECKBYNAME=dr["CHECKBYNAME"].ToString();
				}
				if(dr["CHECKDATE"]!=null && dr["CHECKDATE"].ToString()!="")
				{
					model.CHECKDATE=DateTime.Parse(dr["CHECKDATE"].ToString());
				}
				if(dr["REMARK"]!=null && dr["REMARK"].ToString()!="")
				{
					model.REMARK=dr["REMARK"].ToString();
				}
				if(dr["TOUSER"]!=null && dr["TOUSER"].ToString()!="")
				{
					model.TOUSER=dr["TOUSER"].ToString();
				}
				if(dr["STATUS"]!=null && dr["STATUS"].ToString()!="")
				{
                    model.STATUS = OracleHelper.ToInt(dr["STATUS"].ToString());
				}
				if(dr["LOANSTATUS"]!=null && dr["LOANSTATUS"].ToString()!="")
				{
                    model.LOANSTATUS = OracleHelper.ToInt(dr["LOANSTATUS"].ToString());
				}
				if(dr["CONFIRMBY"]!=null && dr["CONFIRMBY"].ToString()!="")
				{
					model.CONFIRMBY=dr["CONFIRMBY"].ToString();
				}
				if(dr["CONFIRMDATE"]!=null && dr["CONFIRMDATE"].ToString()!="")
				{
					model.CONFIRMDATE=DateTime.Parse(dr["CONFIRMDATE"].ToString());
				}
				if(dr["RETURNSTATUS"]!=null && dr["RETURNSTATUS"].ToString()!="")
				{
                    model.RETURNSTATUS = OracleHelper.ToInt(dr["RETURNSTATUS"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_LOAN_MAIN GetByID(long ID)
		{
			GSLMS.Entity.TB_LOAN_MAIN sModel = new GSLMS.Entity.TB_LOAN_MAIN();
			string sql = "";
			sql = "select * from TB_LOAN_MAIN where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_LOAN_MAIN> GetList(GSLMS.Entity.TB_LOAN_MAIN searchParam)
		{
			var list=new List<GSLMS.Entity.TB_LOAN_MAIN>();
			DataTable dt = null;
			string tblName = "TB_LOAN_MAIN";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_LOAN_MAIN model = new GSLMS.Entity.TB_LOAN_MAIN();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

